<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Ray - Three.js Docs</title>
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<script src="../scripts/highlight.min.js"></script>
	<link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
	<link type="text/css" rel="stylesheet" href="../styles/page.css">
</head>
<body>
	<h1 translate="no">Ray</h1>
		<section>
			<header>
				<div class="class-description"><p>A ray that emits from an origin in a certain direction. The class is used by
<a href="Raycaster.html">Raycaster</a> to assist with raycasting. Raycasting is used for
mouse picking (working out what objects in the 3D space the mouse is over)
amongst other things.</p></div>
			</header>
			<article>
				<div class="container-overview">
					<h2>Constructor</h2>
					<h3 class="name name-method" id="Ray" translate="no">new <a href="#Ray">Ray</a><span class="signature">( origin : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, direction : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Constructs a new ray.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>origin</strong>
									</td>
									<td class="description last">
										<p>The origin of the ray.</p>
										<p>Default is <code>(0,0,0)</code>.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>direction</strong>
									</td>
									<td class="description last">
										<p>The (normalized) direction of the ray.</p>
										<p>Default is <code>(0,0,-1)</code>.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<h2 class="subsection-title">Properties</h2>
				<div class="member">
					<h3 class="name" id="direction" translate="no">.<a href="#direction">direction</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="description">
						<p>The (normalized) direction of the ray.</p>
					</div>
				</div>
				<div class="member">
					<h3 class="name" id="origin" translate="no">.<a href="#origin">origin</a><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="description">
						<p>The origin of the ray.</p>
					</div>
				</div>
				<h2 class="subsection-title">Methods</h2>
					<h3 class="name name-method" id="applyMatrix4" translate="no">.<a href="#applyMatrix4">applyMatrix4</a><span class="signature">( matrix4 : <span class="param-type"><a href="Matrix4.html">Matrix4</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Transforms this ray with the given 4x4 transformation matrix.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>matrix4</strong>
									</td>
									<td class="description last">
										<p>The transformation matrix.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="at" translate="no">.<a href="#at">at</a><span class="signature">( t : <span class="param-type">number</span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns a vector that is located at a given distance along this ray.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>t</strong>
									</td>
									<td class="description last">
										<p>The distance along the ray to retrieve a position for.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A position on the ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns a new ray with copied values from this instance.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="closestPointToPoint" translate="no">.<a href="#closestPointToPoint">closestPointToPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the point along this ray that is closest to the given point.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>point</strong>
									</td>
									<td class="description last">
										<p>A point in 3D space to get the closet location on the ray for.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The closest point on this ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Copies the values of the given ray to this instance.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>ray</strong>
									</td>
									<td class="description last">
										<p>The ray to copy.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="distanceSqToPoint" translate="no">.<a href="#distanceSqToPoint">distanceSqToPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the squared distance of the closest approach between this ray and the given point.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>point</strong>
									</td>
									<td class="description last">
										<p>A point in 3D space to compute the distance to.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="distanceSqToSegment" translate="no">.<a href="#distanceSqToSegment">distanceSqToSegment</a><span class="signature">( v0 : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, v1 : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, optionalPointOnRay : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, optionalPointOnSegment : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the squared distance between this ray and the given line segment.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>v0</strong>
									</td>
									<td class="description last">
										<p>The start point of the line segment.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>v1</strong>
									</td>
									<td class="description last">
										<p>The end point of the line segment.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>optionalPointOnRay</strong>
									</td>
									<td class="description last">
										<p>When provided, it receives the point on this ray that is closest to the segment.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>optionalPointOnSegment</strong>
									</td>
									<td class="description last">
										<p>When provided, it receives the point on the line segment that is closest to this ray.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="distanceToPlane" translate="no">.<a href="#distanceToPlane">distanceToPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span> )</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Computes the distance from the ray's origin to the given plane. Returns <code>null</code> if the ray
does not intersect with the plane.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>plane</strong>
									</td>
									<td class="description last">
										<p>The plane to compute the distance to.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="distanceToPoint" translate="no">.<a href="#distanceToPoint">distanceToPoint</a><span class="signature">( point : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the distance of the closest approach between this ray and the given point.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>point</strong>
									</td>
									<td class="description last">
										<p>A point in 3D space to compute the distance to.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The distance.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( ray : <span class="param-type"><a href="Ray.html">Ray</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns <code>true</code> if this ray is equal with the given one.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>ray</strong>
									</td>
									<td class="description last">
										<p>The ray to test for equality.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> Whether this ray is equal with the given one.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectBox" translate="no">.<a href="#intersectBox">intersectBox</a><span class="signature">( box : <span class="param-type"><a href="Box3.html">Box3</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Intersects this ray with the given bounding box, returning the intersection
point or <code>null</code> if there is no intersection.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>box</strong>
									</td>
									<td class="description last">
										<p>The box to intersect.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectPlane" translate="no">.<a href="#intersectPlane">intersectPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Intersects this ray with the given plane, returning the intersection
point or <code>null</code> if there is no intersection.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>plane</strong>
									</td>
									<td class="description last">
										<p>The plane to intersect.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectSphere" translate="no">.<a href="#intersectSphere">intersectSphere</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Intersects this ray with the given sphere, returning the intersection
point or <code>null</code> if there is no intersection.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>sphere</strong>
									</td>
									<td class="description last">
										<p>The sphere to intersect.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectTriangle" translate="no">.<a href="#intersectTriangle">intersectTriangle</a><span class="signature">( a : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, b : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, c : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, backfaceCulling : <span class="param-type">boolean</span>, target : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Vector3.html">Vector3</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Intersects this ray with the given triangle, returning the intersection
point or <code>null</code> if there is no intersection.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>a</strong>
									</td>
									<td class="description last">
										<p>The first vertex of the triangle.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>b</strong>
									</td>
									<td class="description last">
										<p>The second vertex of the triangle.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>c</strong>
									</td>
									<td class="description last">
										<p>The third vertex of the triangle.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>backfaceCulling</strong>
									</td>
									<td class="description last">
										<p>Whether to use backface culling or not.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>target</strong>
									</td>
									<td class="description last">
										<p>The target vector that is used to store the method's result.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The intersection point.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectsBox" translate="no">.<a href="#intersectsBox">intersectsBox</a><span class="signature">( box : <span class="param-type"><a href="Box3.html">Box3</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns <code>true</code> if this ray intersects with the given box.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>box</strong>
									</td>
									<td class="description last">
										<p>The box to intersect.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given box or not.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectsPlane" translate="no">.<a href="#intersectsPlane">intersectsPlane</a><span class="signature">( plane : <span class="param-type"><a href="Plane.html">Plane</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns <code>true</code> if this ray intersects with the given plane.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>plane</strong>
									</td>
									<td class="description last">
										<p>The plane to intersect.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given plane or not.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="intersectsSphere" translate="no">.<a href="#intersectsSphere">intersectsSphere</a><span class="signature">( sphere : <span class="param-type"><a href="Sphere.html">Sphere</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns <code>true</code> if this ray intersects with the given sphere.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>sphere</strong>
									</td>
									<td class="description last">
										<p>The sphere to intersect.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> Whether this ray intersects with the given sphere or not.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="lookAt" translate="no">.<a href="#lookAt">lookAt</a><span class="signature">( v : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Adjusts the direction of the ray to point at the given vector in world space.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>v</strong>
									</td>
									<td class="description last">
										<p>The target position.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="recast" translate="no">.<a href="#recast">recast</a><span class="signature">( t : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Shift the origin of this ray along its direction by the given distance.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>t</strong>
									</td>
									<td class="description last">
										<p>The distance along the ray to interpolate.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( origin : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, direction : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Ray.html">Ray</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Sets the ray's components by copying the given values.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>origin</strong>
									</td>
									<td class="description last">
										<p>The origin.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>direction</strong>
									</td>
									<td class="description last">
										<p>The direction.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this ray.</dt>
						</dl>
					</div>
				<h2 class="subsection-title">Source</h2>
				<p>
					<a href="https://github.com/mrdoob/three.js/blob/master/src/math/Ray.js" translate="no" target="_blank" rel="noopener">src/math/Ray.js</a>
				</p>
			</article>
		</section>
<script src="../scripts/linenumber.js"></script>
<script src="../scripts/page.js"></script>
</body>
</html>